package com.donfu.web.controller.house;

import java.util.Date;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.donfu.common.annotation.Log;
import com.donfu.common.core.controller.BaseController;
import com.donfu.common.core.domain.AjaxResult;
import com.donfu.common.enums.BusinessType;
import com.donfu.system.domain.house.HouseNovelty;
import com.donfu.system.service.house.IHouseNoveltyService;
import com.donfu.common.utils.poi.ExcelUtil;
import com.donfu.common.core.page.TableDataInfo;

/**
 * 品牌文章Controller
 * 
 * @author donfu
 * @date 2021-12-01
 */
@Api(tags = "后台-品牌文章管理")
@RestController
@RequestMapping("/house/novelty")
public class HouseNoveltyController extends BaseController
{
    @Autowired
    private IHouseNoveltyService houseNoveltyService;

    /**
     * 查询品牌文章列表
     */
    @PreAuthorize("@ss.hasPermi('house:novelty:list')")
    @ApiOperation("列表查询")
    @GetMapping("/list")
    public TableDataInfo list(HouseNovelty houseNovelty)
    {
        startPage();
        List<HouseNovelty> list = houseNoveltyService.selectHouseNoveltyList(houseNovelty);
        return getDataTable(list);
    }

    /**
     * 导出品牌文章列表
     */
    @PreAuthorize("@ss.hasPermi('house:novelty:export')")
    @ApiOperation("导出")
    @Log(title = "品牌文章", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HouseNovelty houseNovelty)
    {
        List<HouseNovelty> list = houseNoveltyService.selectHouseNoveltyList(houseNovelty);
        ExcelUtil<HouseNovelty> util = new ExcelUtil<HouseNovelty>(HouseNovelty.class);
        return util.exportExcel(list, "品牌文章数据");
    }

    /**
     * 获取品牌文章详细信息
     */
    @PreAuthorize("@ss.hasPermi('house:novelty:query')")
    @ApiOperation("详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(houseNoveltyService.selectHouseNoveltyById(id));
    }

    /**
     * 新增品牌文章
     */
    @PreAuthorize("@ss.hasPermi('house:novelty:add')")
    @ApiOperation("新增")
    @Log(title = "品牌文章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseNovelty houseNovelty)
    {
        houseNovelty.setCreateDate(new Date());
        return toAjax(houseNoveltyService.insertHouseNovelty(houseNovelty));
    }

    /**
     * 修改品牌文章
     */
    @PreAuthorize("@ss.hasPermi('house:novelty:edit')")
    @ApiOperation("修改")
    @Log(title = "品牌文章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseNovelty houseNovelty)
    {
        houseNovelty.setUpdateDate(new Date());
        return toAjax(houseNoveltyService.updateHouseNovelty(houseNovelty));
    }

    /**
     * 删除品牌文章
     */
    @PreAuthorize("@ss.hasPermi('house:novelty:remove')")
    @ApiOperation("删除")
    @Log(title = "品牌文章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(houseNoveltyService.deleteHouseNoveltyByIds(ids));
    }
}
